<template>
    <div>
        <!-- 顶部导航部分 -->
        <div id="slider" class="mui-slider ">
            <!-- mui-fullscreen 此类使页面全屏 -->
            <div id="sliderSegmentedControl" class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted">
                <div class="mui-scroll">
                    <a :class="['mui-control-item',i==0 ? 'mui-active' : '']" href="#item1mobile" data-wid="tab-top-subpage-1.html" v-for="(itemBar,i) in topBar" :key="itemBar.id" @click="getPhotoListByCateId(itemBar.id)">
                        {{itemBar.title}}
                    </a>
                </div>
            </div>
        </div>
<!-- 图片列表区域 -->
        <ul class="photo-list">
            <li v-for="item in imglist.list" :key="item.id">
                <router-link :to="'/home/photoinfo/'+item.id">
                    <img v-lazy="item.img">
                    <div class="info">
                        <h1 class="info-title">
                            {{imglist.title}}
                        </h1>
                        <div class="info-body">
                            {{item.imgInfo}}
                        </div>
                    </div>
                </router-link>
                
            </li>
        </ul>
    </div>
</template>
<style lang='scss' scoped>
*{touch-action: pan-y}
// 上述样式只使用谷歌

.photo-list{
    list-style: none;
    padding: 10px;
    margin: 0;
    padding-bottom: 0px;
    li{
        background: #ccc;
        text-align: center;
        margin-bottom: 10px;
        box-shadow: 0 0 9px #999;
        position: relative;
        img{
            width: 100%;
            vertical-align: middle;
        }
        img[lazy=loading] {
            width: 40px;
            height: 300px;
            margin: auto;
        }
        .info{
            color:#fff;
            text-align: left;
            position: absolute;
            left:0;
            bottom:0;
            width: 100%;
            padding: 10px 5px;
            background: rgba(0,0,0,0.4);
            max-height: 84px;
            .info-title{
                font-size: 14px;
            }
            .info-body{
                font-size: 12px;
                line-height: 20px
            }
        }
    }
    
}
</style>
<script>
// 1.导入mui.js
import mui from  "../../lib/mui/js/mui.min.js";
// 2.初始化滑动

export default {
    data(){
        return {
            topBar:[],
            imglist:[]
        }
    },
    methods:{
        photoTopBar(){
            var that = this;
            that.$http.get('../../data/photoTopBar.json').then(res=>{
                // console.log(res)
                if(res.body.code == 200){
                    that.topBar = res.body.list
                    // console.log(that.topBar)
                }
                
            })
        },
        getPhotoListByCateId(cateid){
            // this.$http.get('url'+cateid).then(res=>{
            //     if(res.body.code == 200){
            //         this.list = res.body.list
            //     }
            // })
            var that = this;
            that.$http.get('../../data/photolist.json').then(res=>{
                
                if(res.status == 200){
                    // this.list = res.body.list;
                    var photolist = res.body
                    for(var i=0;i<photolist.length;i++){
                        console.log(cateid,'------',photolist[i].id)
                        if(cateid == photolist[i].id){
                            that.imglist = photolist[i]
                            break
                        }
                        
                    }
                    console.log(that.imglist)
                }
            })

        }
    },
    created(){
        this.photoTopBar();
        // 默认的全部分类
        this.getPhotoListByCateId(0)
    },
    mounted(){
        mui('.mui-scroll-wrapper').scroll({
            deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
        });
        this.photoTopBar()
    }
}

</script>